package com.better.common.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/12/26.
 */
public class FixedValiator implements ConstraintValidator<Fixed, String> {
    String splittag=",";
   Map<String,String> map=new HashMap<String,String>();
    @Override
    public void initialize(Fixed constraintAnnotation) {
        String value= constraintAnnotation.value();
        String[] ss=value.split(splittag);
        for (String key:ss){
            map.put(key,key);
        }

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if(map.containsKey(value))
            return true;
        return false;
    }

}
